package com.baidu.service;

import com.baidu.aip.face.AipFace;
import com.baidu.aip.nlp.AipNlp;
import com.baidu.aip.util.Base64Util;
import com.baidu.utils.AipFaceSample;
import com.baidu.utils.AipNlpSample;
import org.json.JSONObject;

import java.util.HashMap;

// AipFaceService 人脸识别业务处理类
public class AipNlpService {

    // 优化：免实例化对象, 单例模式
    private static AipNlpService aipNlpService;
    public static AipNlpService getAipNlpService(){
        if(aipNlpService == null) aipNlpService = new AipNlpService();
        return aipNlpService;
    }

    public AipNlp aipNlp = AipNlpSample.getAipNlp();

    //地址识别
    public String address(String text) {
        // 传入可选参数调用接口
        HashMap<String, Object> options = new HashMap<>();

        JSONObject json = aipNlp.address(text, options);
        System.out.println(json.toString(2));
        return  json.toString();
    }
    public String affectiveAnalysis(String text) {
        // 传入可选参数调用接口
        HashMap<String, Object> options = new HashMap<>();
        // 情感倾向分析
        JSONObject res = aipNlp.sentimentClassify(text, options);
        System.out.println(res.toString(2));
        return res.toString();
    }

}

